package open3366pvp.as3
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.system.System;
	import flash.utils.ByteArray;
	
	import open3366pvp.as3.dataStruct.IPvpInfo;

	public class Open3366PvpApi
	{
		private static const MAX_MSG_LEN:int = 4096;
		private static const MAX_BUFFER_LEN:int = 1024;
		private static const MAX_MASS_LEN:int = 50;
		private static const MAX_NICK_LEN:int = 64;
		
		/**
		 * 初始化游戏参数 ,加载组件swf,给用户提供的接口
		 * @param szUid 游戏用户ID
		 * @param uiTimeStamp 鉴权用时间戳
		 * @param szAccessToken 鉴权token
		 * @param uiGameId 游戏ID
		 * @param dis 游戏的主容器（主要用于获取沙箱环境）
		 */		
		public static function initGame(szUid:String, uiTimeStamp:uint, szAccessToken:String, uiGameId:uint, dis:Sprite = null):void
		{
			if(szUid && szAccessToken && checkInt(uiTimeStamp) && checkInt(uiGameId))
			{
				trace("调用接口initGame。传入参数： uid=" + szUid + ", timeStamp=" + uiTimeStamp + ", token=" + szAccessToken + ", gameId=" + uiGameId);
				Open3366PvpCore.init(szUid, uiTimeStamp, szAccessToken, uiGameId, dis);
			}else
			{
				trace("传入的参数uid或者token为空");
				dispatchEvent(new Open3366PvpEvent(Open3366PvpEvent.SOCKET_ERROR, 4));
			}
		}
		
		/**
		 * pvp服务器断开之后重连 
		 * 
		 */		
		public static function reconnect():void
		{
			if(Open3366PvpCore.service)
			{
				trace("调用接口reconnect。");
				Open3366PvpCore.service.reconnect();
			}else
			{
				asDispatcherEvent(202);
				trace("调用接口reconnect。但还未初始化组件");
			}
		}
		
		/**
		 * 获取所有区列表
		 * 
		 */		
		public static function getZoneList():void
		{
			if(Open3366PvpCore.service)
			{
				trace("调用接口getZoneList。");
				Open3366PvpCore.service.getZoneList();
			}else
			{
				asDispatcherEvent(3);
				trace("调用接口getZoneList。但还未初始化组件");
			}
		}
		
		/**
		 * 快速进入游戏 
		 * @param zoneId快速进入的区号（默认为-1服务器将为其推荐区）
		 * @param roomId快速进入的房间号（默认为-1服务器将为其推荐房间）
		 * @param tableId快速进入的桌子号（默认为-1服务器将为其推荐桌子）
		 * 
		 */			
		public static function quickEnterGame(zoneId:int = -1, roomId:int = -1, tableId:int = -1):void
		{
			if(Open3366PvpCore.service && checkInt(zoneId) && checkInt(roomId) && checkInt(tableId))
			{
				trace("调用接口quickEnterGame。传入参数：zoneId="+zoneId+",roomId=" + roomId+",tableId="+tableId);
				Open3366PvpCore.service.quickEnterGame(zoneId, roomId, tableId);
			}else
			{
				trace("调用接口quickEnterGame。但还未初始化组件");
				asDispatcherEvent(303);
			}
		}
		
		/**
		 * 根据指定zoneId进入游戏 （进入游戏的指定区）
		 * @param zoneId 
		 * （ zoneId若小于1，则服务器会推荐一个区进入，
		 * 若指定的区当前人数已达到区允许的最大人数，则返回错误码） 
		 */			
		public static function enterZone(zoneId:int):void
		{
			if(Open3366PvpCore.service && checkInt(zoneId))
			{
				trace("调用接口enterZone。传入参数：zoneId="+zoneId);
				Open3366PvpCore.service.enterZone(zoneId);
			}else
			{
				trace("调用接口enterZone。但还未初始化组件");
				asDispatcherEvent(300);
			}
		}
		
		/**
		 * 进入游戏的一个房间（路线）
		 * @param roomId:int  房间（路线）号 （roomId若小于1则服务器推荐个房间）
		 * @param isCreate:int  如果指定的roomId对应好房间不存在是否创建 1创建 其它不创建
		 */
		public static function enterRoom(roomId:int, isCreate:int = 1):void
		{
			if (Open3366PvpCore.service && checkInt(roomId, 1) && checkInt(isCreate))
			{
				trace("调用接口enterRoom。传入参数：roomId="+roomId+",isCreate="+isCreate);
				Open3366PvpCore.service.send(301, roomId, isCreate);
			}else
			{
				trace("调用接口enterRoom。未初始化组件或者传入的参数不正确");
				asDispatcherEvent(301);
			}
		}
		
		/**
		 *进入房间（路线）内的一个桌子（场景）
		 * @param	tableId:int  桌子号 (必须大于0)
		 * @param isCreate:int  如果指定的roomId对应好房间不存在是否创建 1创建 其它不创建
		 */
		public static function enterTable(tableId:int, isCreate:int = 1):void
		{
			if (Open3366PvpCore.service && checkInt(tableId, 1) && checkInt(isCreate))
			{
				trace("调用接口enterTable。传入参数：tableId="+tableId+",isCreate="+isCreate);
				Open3366PvpCore.service.send(302, -1, tableId, isCreate);
			}else
			{
				trace("调用接口enterTable。未初始化组件或者传入的参数不正确");
				asDispatcherEvent(302);
			}
		}
		
		/**
		 * 快速进入桌子（场景），如用户已在某房间（路线）或桌子（场景）则退出当前房间（路线）桌子（场景）进入新的房间（路线）桌子（场景）。 
		 * @param roomId  若<1则服务器推荐房间（路线）若不存在则会主动创建房间（路线）
		 * @param tableId 若<1则服务器推荐桌子（场景）若不存在则会主动创建桌子（场景）
		 * 
		 */		
		public static function quickEnterTable(roomId:int = -1, tableId:int = -1):void
		{
			if (Open3366PvpCore.service && checkInt(tableId) && checkInt(roomId))
			{
				trace("调用接口quickEnterTable。传入参数：roomId="+roomId+",tableId="+tableId);
				Open3366PvpCore.service.send(303, roomId, tableId);
			}else
			{
				asDispatcherEvent(303);
				trace("调用接口quickEnterTable。但还未初始化组件");
			}
		}
		
		/**
		 * 设置游戏区属性
		 * @param  content:ByteArray 游戏区属性
		 */
		public static function setZoneProp(content:ByteArray):void
		{
			if (Open3366PvpCore.service && checkByteArray(content, MAX_BUFFER_LEN))
			{
				trace("调用接口setZoneProp。传入参数：content="+content.toString());
				Open3366PvpCore.service.send(304, content.length, content);
			}else
			{
				trace("调用接口setZoneProp。未初始化组件或者参数传入不对");
				asDispatcherEvent(304);
			}
		}
		
		/**
		 * 创建并设置游戏房间属性
		 * @param	roomId:int  房间号 (必须大于0)
		 * @param  content:ByteArray 游戏房间属性
		 */
		public static function createAndSetRoomProp(roomId:int, content:ByteArray):void
		{
			if (Open3366PvpCore.service && checkInt(roomId, 1) && checkByteArray(content, MAX_BUFFER_LEN))
			{
				trace("调用接口createAndSetRoomProp。传入参数：content="+content.toString()+",roomId="+roomId);
				Open3366PvpCore.service.send(305, roomId, content.length, content);
			}else
			{
				trace("调用接口createAndSetRoomProp。未初始化组件或者参数传入不对");
				asDispatcherEvent(305);
			}
		}
		
		/**
		 * 创建并设置游戏桌子属性
		 * @param	roomId:int  房间号(必须大于0)
		 * @param   tableId:int 桌子号(必须大于0)
		 * @param  content:ByteArray 游戏桌子属性
		 */
		public static function createAndSetTableProp(roomId:int, tableId:int, content:ByteArray):void
		{
			if (Open3366PvpCore.service && checkInt(roomId, 1) && checkInt(tableId, 1) && checkByteArray(content, MAX_BUFFER_LEN))
			{
				trace("调用接口createAndSetTableProp。传入参数：content="+content.toString()+",roomId="+roomId+",tableId"+tableId);
				Open3366PvpCore.service.send(306, roomId, tableId, content.length, content);
			}else
			{
				trace("调用接口createAndSetTableProp。未初始化组件或者参数传入不对");
				asDispatcherEvent(306);
			}
		}
		
		/**
		 * 设置游戏用户自己属性
		 * @param  niack  用户昵称不能为空
		 * @param  content:ByteArray 用户属性
		 */
		public static function setUserProp(nick:String,content:ByteArray):void
		{
			if (Open3366PvpCore.service && checkByteArray(content, MAX_BUFFER_LEN) && nick && getStrLen(nick) <= MAX_NICK_LEN)
			{
				var nickData:ByteArray = new ByteArray();
				nickData.writeInt(getStrLen(nick));
				nickData.writeUTFBytes(nick);
				trace("调用接口setUserProp。传入参数：content="+content.toString()+",nick="+nick);
				Open3366PvpCore.service.send(307, nickData, content.length, content);
			}else
			{
				trace("调用接口setUserProp。未初始化组件或者参数传入不对");
				asDispatcherEvent(307);
			}
		}
		
		/**
		 * 获取当前所在区的详细区信息 
		 * 
		 */		
		public static function getZoneInfo():void
		{
			if(Open3366PvpCore.service)
			{
				trace("调用接口getZoneInfo。");
				Open3366PvpCore.service.send(308);
			}else
			{
				trace("调用接口getZoneInfo。但未初始化组件");
				asDispatcherEvent(308);
			}
		}
		
		/**
		 * 获取游戏所有房间
		 */
		public static function getRoomList():void
		{
			if (Open3366PvpCore.service)
			{
				trace("调用接口getRoomList。");
				Open3366PvpCore.service.send(309);
			}else
			{
				trace("调用接口getRoomList。但未初始化组件");
				asDispatcherEvent(309);
			}
		}
		
		/**
		 * 获取游戏单个房间（路线）属性
		 * @param roomId:uint  房间（路线）号(必须大于0)
		 */
		public static function getRoomInfo(roomId:int):void
		{
			if (Open3366PvpCore.service && checkInt(roomId, 1))
			{
				trace("调用接口getRoomInfo。传入参数："+roomId);
				Open3366PvpCore.service.send(310, roomId);
			}else
			{
				trace("调用接口getRoomInfo。未初始化组件或者传入参数不对");
				asDispatcherEvent(310);
			}
		}
		
		/**
		 *  获取游戏批量房间（路线）属性
		 * @param roomList:Array(int) 要获取属性的房间（路线）号数组
		 */
		public static function getMassRoomInfo(roomList:Array):void
		{
			var data:ByteArray = checkArray(roomList, "int");
			if (Open3366PvpCore.service &&  data != null)
			{
				trace("调用接口getMassRoomInfo。传入参数：roomList="+roomList.toString());
				Open3366PvpCore.service.send(311, data);
			}else
			{
				trace("调用接口getMassRoomInfo。未初始化组件或者传入的参数不正确");
				asDispatcherEvent(311);
			}
		}
		 
		 /**
		 * 获取房间（路线）所有桌子（场景）
		 * @param roomId:int  房间号(必须大于0)
		 */
		 public static function getTableList(roomId:int):void
		 {
		 	if (Open3366PvpCore.service && checkInt(roomId, 1))
			{
				trace("调用接口getTableList。传入参数：roomId="+roomId);
				Open3366PvpCore.service.send(312, roomId);
			}else
			{
				trace("调用接口getTableList。未初始化组件或者传入的参数不正确");
				asDispatcherEvent(312);
			}
		 }
		 
		 /**
		 * 获取房间（路线）单个桌子（场景）属性
		 * @param roomId:int  房间号(必须大于0)
		 * @param tableId:int 桌子号(必须大于0)
		 */
		 public static function getTableInfo(roomId:int, tableId:int):void
		 {
		 	if (Open3366PvpCore.service && checkInt(roomId, 1) && checkInt(tableId, 1))
			{
				trace("调用接口getTableInfo。传入参数：roomId="+roomId+",tableId="+tableId);
				Open3366PvpCore.service.send(313, roomId, tableId);
			}else
			{
				trace("调用接口getTableInfo。未初始化组件或者传入的参数不正确");
				asDispatcherEvent(313);
			}
		 }
		 
		 /**
		 * 获取房间批量桌子（场景）属性
		 * @param	roomId:int  房间号(必须大于0)
		 * @param	aiTableId:Array  要获取属性的桌子号数组
		 */
		public static function getMassTableInfo(roomId:int, tableIdList:Array):void
		{
			var data:ByteArray = checkArray(tableIdList, "int");
			if (Open3366PvpCore.service && checkInt(roomId, 1) &&　data != null)
			{
				trace("调用接口getMassTableInfo。传入参数：roomId="+roomId+",tableIdList="+tableIdList.toString());
				Open3366PvpCore.service.send(314, roomId, data);
			}else
			{
				trace("调用接口getMassTableInfo。未初始化组件或者传入的参数不正确");
				asDispatcherEvent(314);
			}
		}
		
		/**
		 * 获取桌子（场景）内的所有用户
		 * @param	roomId:int  房间号 默认为-1表示获取本房间的用户
		 * @param	tableId:int  桌子号默认为-1表示获取本桌子的用户
		 */
		public static function getUserList(roomId:int = -1, tableId:int = -1):void
		{
			if (Open3366PvpCore.service && checkInt(roomId) && checkInt(tableId))
			{
				trace("调用接口getUserList。传入参数：roomId="+roomId+",tableId="+tableId);
				Open3366PvpCore.service.send(315, roomId, tableId);
			}else
			{
				trace("调用接口getUserList。未初始化组件或者传入的参数不正确");
				asDispatcherEvent(315);
			}
		}
		
		/**
		 * 获取单个用户属性
		 * @param	uid:String 需要获取属性的用户id
		 */
		public static function getUserInfo(uid:String):void
		{
			if (Open3366PvpCore.service && uid)
			{
				var byte:ByteArray = new ByteArray();
				byte.writeUTFBytes(uid);
				byte.length = 32;
				trace("调用接口getUserInfo。传入参数：uid="+uid);
				Open3366PvpCore.service.send(316, byte);
			}else
			{
				trace("调用接口getUserInfo。未初始化组件或者传入的参数不正确");
				asDispatcherEvent(316);
			}
		}
		
		/**
		 * 获取批量用户属性
		 * @param	uidList:Array 需要获取属性的用户id数组，元素类型为String
		 */
		public static function getMassUserInfo(uidList:Array):void
		{
			var data:ByteArray = checkArray(uidList, "string");
			if (Open3366PvpCore.service && data != null)
			{
				trace("调用接口getMassUserInfo。传入参数：uidList="+uidList.toString());
				Open3366PvpCore.service.send(317, data);
			}else
			{
				trace("调用接口getMassUserInfo。未初始化组件或者传入的参数不正确");
				asDispatcherEvent(317);
			}
		}
		
		/**
		 * 发送消息给另一个用户 
		 * @param uid 收信人
		 * @param content 发送的内容
		 * 
		 */		
		public static function sendMsgToOther(uid:String, content:ByteArray):int
		{
			if (Open3366PvpCore.service && checkByteArray(content, MAX_MSG_LEN) && uid)
			{
				var byte:ByteArray = new ByteArray();
				byte.writeUTFBytes(uid);
				byte.length = 32;
				trace("调用接口sendMsgToOther。传入参数：content="+content.toString()+", uid=" + uid);
				Open3366PvpCore.service.send(318, byte, content.length, content);
				return 1;
			}else
			{
				trace("调用接口sendMsgToOther。未初始化组件或者传入的参数不正确");
				return -1;
			}
		}
		
		/**
		 * 发送消息给本桌所有用户 
		 * @param roomId 用户所在房间ID 默认为-1表示发送给当前房间
		 * @param tableId 用户所在桌子ID 默认为-1表示发送给当前桌子
		 * @param isSendMe 是否发送给我自己  0不发送，1为发送
		 * @param content 发送的内容
		 * 
		 */		
		public static function sendMsgToTable(content:ByteArray, roomId:int = -1, tableId:int = -1, isSendMe:int = 0):int
		{
			if (Open3366PvpCore.service && checkByteArray(content, MAX_MSG_LEN) && checkInt(roomId) && checkInt(tableId) && checkInt(isSendMe))
			{		
				trace("调用接口sendMsgToTable。传入参数：content="+content.toString()+", roomId=" + roomId+",tableId="+tableId+",isSendMe="+isSendMe);
				Open3366PvpCore.service.send(319, roomId, tableId, isSendMe, content.length, content);
				return 1;
			}else
			{
				trace("调用接口sendMsgToTable。未初始化组件或者传入的参数不正确");
				return -1;
			}
		}
		
		/**
		 * 发消息给本房间的所有用户 
		 * @param roomId 用户所在房间ID 默认为-1表示发送给当前桌子
		 * @param isSendMe 是否发送给我自己  0不发送，非0为发送
		 * @param content 发送的内容
		 * 
		 */		
		public static function sendMsgToRoom(content:ByteArray, roomId:int = -1, isSendMe:int = 0):int
		{
			if (Open3366PvpCore.service && checkByteArray(content, MAX_MSG_LEN) && checkInt(roomId) && checkInt(isSendMe))
			{		
				trace("调用接口sendMsgToRoom。传入参数：content="+content.toString()+", roomId=" + roomId+",isSendMe="+isSendMe);
				Open3366PvpCore.service.send(320, roomId, isSendMe, content.length, content);
				return 1;
			}else
			{
				trace("调用接口sendMsgToRoom。未初始化组件或者传入的参数不正确");
				return -1;
			}
		}
		
		/**
		 * 发消息给本区批量用户 
		 * @param uidList 收信人的ID数组  （不能为null和空）
		 * @param content 发送的内容
		 * 
		 */		
		public static function sendMsgToOthers(uidList:Array, content:ByteArray):int
		{
			var data:ByteArray = checkArray(uidList, "string");
			if (Open3366PvpCore.service && data != null && checkByteArray(content, MAX_MSG_LEN))
			{
				trace("调用接口sendMsgToOthers。传入参数：content="+content.toString()+", uidList=" + uidList.toString());
				Open3366PvpCore.service.send(321, data, content.length, content);
				return 1;
			}else
			{
				trace("调用接口sendMsgToOthers。未初始化组件或者传入的参数不正确");
				return -1;
			}
		}
		
		/**
		 * 发送消息给本区的所有用户 
		 * @param content 发送的内容
		 * @param isSendMe 是否发送给我自己  0不发送，1为发送
		 */			
		public static function sendMsgToZone(content:ByteArray, isSendMe:int = 0):int
		{
			if (Open3366PvpCore.service && checkByteArray(content, MAX_MSG_LEN) && checkInt(isSendMe))
			{		
				trace("调用接口sendMsgToZone。传入参数：content="+content.toString()+", isSendMe=" +isSendMe);
				Open3366PvpCore.service.send(328, isSendMe, content.length, content);
				return 1;
			}else
			{
				trace("调用接口sendMsgToZone。未初始化组件或者传入的参数不正确");
				return -1;
			}
		}
		
		/**
		 * 退出本桌，回到房间节点 
		 * 
		 */		
		public static function quitTable():void
		{
			if (Open3366PvpCore.service)
			{		
				trace("调用接口quitTable。");
				Open3366PvpCore.service.send(323);
			}else
			{
				trace("调用接口quitTable。但还未初始化组件");
				asDispatcherEvent(323);
			}
		}
		
		/**
		 * 退出本房间，回到区节点 
		 * 
		 */		
		public static function quitRoom():void
		{
			if (Open3366PvpCore.service)
			{		
				trace("调用接口quitRoom。");
				Open3366PvpCore.service.send(324);
			}else
			{
				trace("调用接口quitRoom。但还未初始化组件");
				asDispatcherEvent(324);
			}
		}
		
		/**
		 * 退出游戏区，清除服务器端此游戏用户数据 
		 * 
		 */		
		public static function quitZone():void
		{
			if (Open3366PvpCore.service)
			{		
				trace("调用接口quitZone。");
				Open3366PvpCore.service.send(325);
			}else
			{
				trace("调用接口quitZone。但还未初始化组件");
				asDispatcherEvent(325);
			}
		}
		
		/**
		 * 获取邀请模式 (如果获取网页地址失败，则返回null)
		 * @return obj格式如下
		 * obj.inviteMode 邀请模式 0为邀请模式 1为非邀请模式
		 * obj.zoneId 邀请模式下有效， 邀请人所在的区id
		 * obj.roomId 邀请模式下有效， 邀请人所在的房间（路线）id
		 * obj.tableId 邀请模式下有效， 邀请人所在的桌子（场景）id
		 */		
		public static function getInviteMode():Object
		{
			if (Open3366PvpCore.service)
			{		
				var url:String = Open3366PvpCore.service.getGameUrl();
				if(url != "")
				{
					var obj:Object = new Object();
					obj.inviteMode = (argument(url, "zoneId") == ""? 0 : 1);
					obj.zoneId = int(argument(url, "zoneId"));
					obj.roomId = int(argument(url, "roomId"));
					obj.tableId = int(argument(url, "tableId"));
					trace("获取当前游戏地址成功。url=" + url + ", invitMode = " + obj.inviteMode + ", zoneId="+ obj.zoneId + ", roomId="+obj.roomId + ", tableId=" + obj.tableId);
					return obj;
				}
			}
			showAlert("获取游戏地址失败，无法获取邀请模式");
			return null;
		}
		
		/**
		 * 复制连接到剪贴板
		 * @param url
		 * 
		 */		
		public static function copyUrlToFriend(zoneId:int, roomId:int, tableId:int):void
		{
			if (Open3366PvpCore.service && checkInt(zoneId) && checkInt(roomId) && checkInt(tableId))
			{		
				var url:String = Open3366PvpCore.service.getGameUrl();
				if(url != "")
				{
					if(url.indexOf("\?") != -1)
					{
						if(url.indexOf("zoneId") == -1)
						{
							url += "&zoneId=" + zoneId + "&roomId=" + roomId + "&tableId=" + tableId;
						}
					}else
					{
						url += "?zoneId=" + zoneId + "&roomId=" + roomId + "&tableId=" + tableId;
					}
					System.setClipboard(url);
					showAlert("复制游戏地址成功！ url=" + url);
				}else
				{
					showAlert("获取游戏地址失败，无法复制游戏地址到剪贴板");
				}
			}
		}
		
		/**
		 * 弹出邀请qq好友的面板 
		 * @param uiGameId 游戏id
		 * @param zoneId 玩家所在的区id
		 * @param roomId 玩家所在的房间（路线）id
		 * @param tableId 玩家所在的桌子（场景）id
		 * 
		 */			
		public static function showInvitePanel(uiGameId:uint, zoneId:int, roomId:int, tableId:int):void
		{
			if (Open3366PvpCore.service && checkInt(uiGameId) && checkInt(zoneId) && checkInt(roomId) && checkInt(tableId))
			{		
				trace("调用接口showInvitePanel。传入参数：gameId="+uiGameId+",zoneId"+zoneId+",tableId="+tableId);
				Open3366PvpCore.service.inviteFriend(uiGameId, zoneId, roomId, tableId);
			}else
			{
				trace("调用接口showInvitePanel。但还未初始化组件");
			}
		}
		 
		private static var _dispatcher:EventDispatcher = new EventDispatcher();
		
		public static function dispatchEvent(evt:Event):void
		{
			_dispatcher.dispatchEvent(evt);
		}
		
		public static function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
		{
			_dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
		}
		
		public static function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
		{
			_dispatcher.removeEventListener(type, listener, useCapture);
		}
		
		private static function getStrLen(str:String, charSet:String = "utf-8"):int
		{
			var by:ByteArray = new ByteArray();
			by.writeMultiByte(str, charSet);
			return by.length;
		}
		
		/**
		 * 弹出警告框 
		 * @param msg
		 * @param window
		 * 
		 */		
		private static function showAlert(msg:String, window:String = "_self"):void
		{
			navigateToURL(new URLRequest("javascript:alert('"+msg+"')"), window);
		}
		
		/**
		 * 获取url里面的参数 
		 * @param url
		 * @param attribute
		 * @return 
		 * 
		 */		
		private static function argument(url:String, attribute:String):String
		{
			var attributeList:Array = url.substr(url.search("\?")+1).split("&"); 
			for(var i:int = 0; i < attributeList.length; i++)
			{ 
				var keyValueList:Array =attributeList[i].split("="); 
				if(keyValueList[0] == attribute)
				{  
					return keyValueList[1];
				} 
			} 
			return ""; 
		}
		
		private static function asDispatcherEvent(cmdId:int, iRet:int = 20000):void
		{
			var info:IPvpInfo = Open3366PvpConfig.getInfo(cmdId);
			dispatchEvent(new Open3366PvpEvent(info.eventType, {info:info, iRet:iRet}));
		}
		
		private static function checkByteArray(data:ByteArray, maxLen:int):Boolean
		{
			if(data == null)
			{
				data = new ByteArray();
			}
			return (data.length <= maxLen);
		}
		
		private static function checkInt(data:int, min:int = int.MIN_VALUE, max:int = int.MAX_VALUE):Boolean
		{
			if(data > max || data < min)
			{
				return false;
			}
			return true;
		}
		
		private static function checkArray(list:Array, type:String):ByteArray
		{
			if(list == null || list.length > MAX_MASS_LEN)
			{
				return null;
			}
			var len:int = list.length;
			var data:ByteArray = new ByteArray();
			data.writeInt(len);
			for(var i:int = 0; i < len; i++)
			{
				if(type == "int")
				{
					data.writeInt(list[i]);
				}else if(type == "string")
				{
					var uid:ByteArray = new ByteArray();
					uid.writeUTFBytes(list[i]);
					uid.length = 32;
					data.writeBytes(uid);
				}
			}
			return data;
		}
	}
}